package com.pyip.reggie.controller;

import com.pyip.reggie.Entity.ShoppingCart;
import com.pyip.reggie.common.R;
import com.pyip.reggie.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

/**
 * 用于文件图片的上传及下载
 */
@RestController
@RequestMapping("/shoppingCart")
@Slf4j
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;


    /**
     * 添加购物车信息，有则+1，无则添加
     * @param shoppingCart
     * @return
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public R<ShoppingCart> addShoppingCart(@RequestBody ShoppingCart shoppingCart){
        log.info("Shopping Cart is {}",shoppingCart);
        return shoppingCartService.addShoppingCart(shoppingCart);
    }

    /**
     * 根据用户id查找所有的购物车信息
     * @return
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public R<List<ShoppingCart>> getShoppingCartList(){
        log.info("查看购物车");
        return shoppingCartService.getShoppingCartList();
    }

    /**
     * 清空购物车
     * @return
     */
    @RequestMapping(value = "/clean",method = RequestMethod.DELETE)
    public R<String> removeShoppingCart(){
        return shoppingCartService.removeShoppingCart();
    }



}
